/*
 * @lc app=leetcode.cn id=2068 lang=typescript
 *
 * [2068] 检查两个字符串是否几乎相等
 */

// @lc code=start
function checkAlmostEquivalent(word1: string, word2: string): boolean {
    const arr0 = new Array(26).fill(0);
    const arr1 = new Array(26).fill(0);
    for (let i = 0; i < word1.length; i++) {
        const element = word1[i];
        arr0[element.charCodeAt(0) - 97]++;
    }
    for (let i = 0; i < word2.length; i++) {
        const element = word2[i];
        const index = element.charCodeAt(0) - 97;
        arr1[index]++;
    }
    return arr1.every((i, index) => {
        return Math.abs(i - arr0[index]) <= 3;
    });
}
// @lc code=end
